package com.scau.clothes.config;
import com.scau.clothes.storage.MinioStorage;
import com.scau.clothes.storage.Storage;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "oss.minio", name = "active", havingValue = "true")
@ConditionalOnClass(MinioClient.class)
public class MinioConfiguration {
    @Bean
    @Qualifier("minioStorage")
    Storage minioStorage(OssProperties ossProperties) {
        OssProperties.Minio minio = ossProperties.getMinio();
        MinioClient minioClient = new MinioClient.Builder()
                .credentials(minio.getAccessKey(), minio.getSecretKey())
                .endpoint(minio.getEndpoint())
                .build();
        return new MinioStorage(minioClient);
    }
}
